﻿
using DataService.Core.DataHelper;
using DataService.Core.Log;
using DataService.Core.Network;
using System;


namespace DataService.Core.Common
{
    public static class SysConfig
    {

        /// <summary>应用实例。单应用多实例部署时用于唯一标识实例节点</summary>
        public static int GetNode()
        {
            int node = 0;
            try
            {
                var ip = NetHelper.MyIP4();
                var buf = ip.GetAddressBytes();
            // TraceLog.WriteLine ($"IP:{ip.GetAddress()}**{buf[2]}**{buf[3]},**{ip.ToString()}");
                node = (buf[2] << 8) | buf[3];
            }
            catch
            {
                // 异常时随机
                node = RandHelper.Next(1, 1024);
                Console.WriteLine($"获取异常节点数：{node}");
                TraceLog.WriteLine($"获取异常节点数：{node}");
            }
            return node;
        }
    }
}
